﻿@using Scada.Web.TreeView
@inject IWebContext webContext
@inject IUserContext userContext
@{
    Layout = "_BasicLayout";
    dynamic dict = Locale.GetDictionary("Scada.Web.Pages.Shared._MainLayout");
    var displayOptions = webContext.AppConfig.DisplayOptions;
    var userID = userContext.UserEntity.UserID;
    var username = userContext.UserEntity.Name;
    var userProfileUrl = webContext.PluginHolder.FeaturedPlugins.UserManagementPlugin?.Features?.UserProfileUrl;

    if (string.IsNullOrEmpty(userProfileUrl))
        userProfileUrl = "/UserProfile";
}

@section Styles {
    <link href="~/css/layouts/main-layout.min.css" rel="stylesheet" asp-append-version="true" />

    @RenderSection("Styles", required: false)

    @foreach (string url in webContext.PluginHolder.AllStyleUrls())
    {
        <link href="@url" rel="stylesheet" asp-append-version="true" />
    }
}

@section Scripts {
    <script src="~/js/components/modal.js" asp-append-version="true"></script>
    <script src="~/js/components/notif-panel.js" asp-append-version="true"></script>
    <script src="~/js/components/tree-view.js" asp-append-version="true"></script>
    <script src="~/js/layouts/main-layout.js" asp-append-version="true"></script>
    <script>
        appEnv = @WebUtils.GetEnvironmentJs(Url);
        modalPhrases = @WebUtils.DictionaryToJs("Scada.Web.Pages.Shared._MainLayout.Modal");
        notifPhrases = @WebUtils.DictionaryToJs("Scada.Web.Pages.Shared._MainLayout.NotifPanel");
    </script>

    @RenderSection("Scripts", required: false)

    @foreach (string url in webContext.PluginHolder.AllScriptUrls())
    {
        <script src="@url" asp-append-version="true"></script>
    }
}

@if (displayOptions.ShowHeader)
{
    <div id="Main_divHeader">
        <div class="main-hdr-block left">@*
            *@<span id="Main_spanMenuBtn" class="main-hdr-btn" title="@dict.spanMenuBtn_ToolTip"><i class="fas fa-bars"></i></span>@*
            *@<span id="Main_spanAppTitle">@CommonPhrases.ProductName</span>
        </div>

        <div class="main-hdr-block right">@*
            *@<span id="Main_spanNotifBtn" class="main-hdr-btn notif-bell" title="@dict.spanNotifBtn_ToolTip"><i class="far fa-bell"></i></span>@*
            *@<a asp-page="@userProfileUrl" asp-route-id="@userID"><span id="Main_spanProfileBtn" class="main-hdr-btn">@username</span></a>@*
            *@<a asp-page="/Logout"><span id="Main_spanLogoutBtn" class="main-hdr-btn">@dict.spanLogoutBtn</span></a>@*
            *@<span id="Main_spanFullscreenBtn" class="main-hdr-btn" title="@dict.spanFullscreenBtn_ToolTip"><i class="fas fa-expand"></i></span>
        </div>
    </div>
}

<div id="Main_divNoHeaderMenu">@*
    *@<span id="Main_spanMenuBtn2" class="main-hdr-btn" title="@dict.spanMenuBtn_ToolTip"><i class="fas fa-bars"></i></span>@*
    *@<span id="Main_spanNotifBtn2" class="main-hdr-btn notif-bell" title="@dict.spanNotifBtn_ToolTip"><i class="far fa-bell"></i></span>@*
    *@<a asp-page="@userProfileUrl" asp-route-id="@userID"><span id="Main_spanProfileBtn2" class="main-hdr-btn" title="@dict.spanProfileBtn_ToolTip"><i class="fas fa-user"></i></span></a>@*
    *@<a asp-page="/Logout"><span id="Main_spanLogoutBtn2" class="main-hdr-btn" title="@dict.spanLogoutBtn_ToolTip"><i class="fas fa-sign-out-alt"></i></span></a>@*
    *@<span id="Main_spanFullscreenBtn2" class="main-hdr-btn" title="@dict.spanFullscreenBtn_ToolTip"><i class="fas fa-expand"></i></span>@*
    *@<span id="Main_spanExitFullscreenBtn" class="main-hdr-btn" title="@dict.spanExitFullscreenBtn_ToolTip"><i class="fas fa-compress"></i></span>
</div>

@if (displayOptions.ShowMainMenu || displayOptions.ShowViewExplorer)
{
    <div id="Main_divLeftPanel">
        <div id="Main_divTabPanel">
            <div id="Main_divMainMenuTab" class="tab" data-tool-window="Main_divMainMenu">@dict.divMainMenuTab</div>
            <div id="Main_divViewExplorerTab" class="tab" data-tool-window="Main_divViewExplorer">@dict.divViewExplorerTab</div>
        </div>
        @if (displayOptions.ShowMainMenu)
        {
            var menuRenderer = new TreeViewRenderer(Url) { SelectedObject = ViewContext.HttpContext.Request.Path };
            var mainMenu = userContext.Menu.MenuItems;
            //var mainMenu = TreeViewExample.GetMainMenu();

            <div id="Main_divMainMenu" class="tool-window hidden">@menuRenderer.RenderHtml(mainMenu)</div>
        }
        @if (displayOptions.ShowViewExplorer)
        {
            var explorerRenderer = new TreeViewRenderer(Url, new TreeViewRenderer.Options
            {
                ExpanderLeft = true,
                ShowIcons = true,
                FolderIconUrl = "~/images/treeview/folder.png",
                NodeIconUrl = "~/images/treeview/document.png"
            })
            {
                SelectedObject = ViewBag.SelectedViewID
            };

            var viewExplorer = userContext.Views.ViewNodes;
            //var viewExplorer = TreeViewExample.GetViewExplorer();

            <div id="Main_divViewExplorer" class="tool-window hidden">@explorerRenderer.RenderHtml(viewExplorer)</div> 
        }
    </div>
}

<div id="Main_divContent" class="link-colored">
    @RenderBody()
</div>

@if (webContext.PluginHolder.FeaturedPlugins.NotificationPlugin != null)
{
    <div id="Main_divNotifPanel" class="notif-panel hidden"></div>
}

@if (webContext.AppConfig.GeneralOptions.ShareStats)
{
    <iframe id="Main_frameStats" src="https://rapidscada.net/stats/?serverID=@webContext.StatsID"></iframe>
}
